from django_mongodb_engine.storage import GridFSStorage
from gridfs import GridFS
import os
import random
import time
class MyGridFSStorage(GridFSStorage):
    
    def _save(self, path, content):
        """
        Saves `content` into the file at `path`.
        """
        gridfs = GridFS(self._db, self.collection)
        ext = os.path.splitext(path)[1]
        file_name = time.strftime('%Y%m%d%H%M%S')  
        file_name = file_name + '%d' % random.randint(0,100)+ext
        gridfs.put(content, filename=file_name)
        return file_name